package com.ruoyi.management.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.management.domain.InvoiceRequest;
import com.ruoyi.management.service.InvoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api")
public class InvoiceController {
    @Autowired
    private InvoiceService invoiceService;

    @PostMapping("/invoice")
    public String recognizeInvoice(@RequestBody InvoiceRequest invoiceRequest ) {
        String base64Image =  invoiceRequest.getBase64Image();
        return  invoiceService.recognizeGeneralInvoice(base64Image);
    }
    @PostMapping("/saveLocalFile")
    public AjaxResult saveLocalFile(@RequestParam("file") MultipartFile file,@RequestParam("type") String typefile) {
        return AjaxResult.success(invoiceService.saveLocalfile(file,typefile));
    }
    @PostMapping("/saveLocalFilemultiple")
    public AjaxResult saveLocalFile(@RequestParam("files") MultipartFile[] files){
        String typefile = "fp";
        List<String> pathList = new ArrayList<String>();
         for(int i=0;i<files.length;i++){
             String path = invoiceService.saveLocalfile(files[i],typefile);
             pathList.add(path);
         }
        return AjaxResult.success(pathList);
    }
    @PostMapping("/saveSqfile")
    public String saveSqfile(@RequestBody InvoiceRequest invoiceRequest) {
        String base64Image =  invoiceRequest.getBase64Image();
        return  invoiceService.recognizeTableOCR(base64Image);
    }
    /**
     *上传发票gs
     * */
    @PostMapping("/saveLocalFilefp")
    public AjaxResult saveLocalFile(@RequestParam("file") MultipartFile file) {
        return AjaxResult.success(invoiceService.saveLocalfilefp(file));
    }
}
